package org.footballmanager.pandafootball.system.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.footballmanager.pandafootball.system.domain.FootMission;
import org.footballmanager.pandafootball.system.domain.FootMissionHistory;
import org.footballmanager.pandafootball.system.service.FootMissionHistoryService;
import org.footballmanager.pandafootball.system.service.FootMissionService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class FootMissionHistoryServiceImpl extends ServiceImpl<FootMissionHistory> implements FootMissionHistoryService {
    @Autowired
    private FootMissionService footMissionService;

    @Scheduled(cron="0 0 0 * * ?") //每天0点触发
    @Override
    public void processHistoryRecord() {
        List<FootMission> list = footMissionService.getall();
        if(list != null && !list.isEmpty()){
            for(FootMission mission: list){
                FootMissionHistory history = new FootMissionHistory();
                BeanUtils.copyProperties(mission, history);
                this.save(history, null);
                footMissionService.delete(mission.getId(), null);
            }
        }
    }
}
